package com.job.blossom;



import java.util.Arrays;
import java.util.Scanner;
/**
 * @author asus
 * @version 1.0
 * @since 2022-07-02 19:57:42
 */
public class Homework0701 {
    public static void main(String[] args) {

        int a = 10;

        Scanner sc = new Scanner(System.in);
        System.out.println("输入你要玩游戏的数字：");
        int n = sc.nextInt();
        int victoryNumber =Homework0701.getVictoryNumber(n);
        System.out.println("最后剩下：" + victoryNumber);


//       给定数组，进行降序排列

//        选择排序法
        int[] arr1 = {1, 15, 5, 4, 9};
        for (int i = 0; i < arr1.length; i++) {
            for (int k = i + 1; k < arr1.length; k++) {

                if (arr1[i] < arr1[k]) {
                    int temp = arr1[k];

                    arr1[k] = arr1[i];

                    arr1[i] = temp;
                }

            }

        }
        System.out.println(Arrays.toString(arr1));


//        冒泡排序法
        int[] array2 = {11, 22, 45, 5, 6, 99};
        for (int i = 0; i < array2.length - 1; i++) {

            for (int j = 0; j < array2.length - i - 1; j++) {
                if (array2[j] < array2[j + 1]) {
                    int t = array2[j + 1];
                    array2[j + 1] = array2[j];
                    array2[j] = t;
                }
            }

        }
        System.out.println(Arrays.toString(array2));


    }

    //玩游戏返回胜利的人的数值编号
//    返回值为 int
//    将数组想象为可以围成圈的样子
    public static int getVictoryNumber(int n) {
        int[] persons = new int[n];
//        为人们赋值  1.2.3.4.5......n;
        for (int i = 0; i < persons.length; i++) {
            persons[i] = i + 1;

        }
//        玩游戏
        while (persons.length > 3) {
//            下一轮
            int[] newPersons = new int[persons.length - 1];
            for (int i = 3; i < persons.length; i++) {
                newPersons[i - 3] = persons[i];
            }
            newPersons[newPersons.length - 2] = persons[0];
            newPersons[newPersons.length - 1] = persons[1];
//            persons 换引用地址为 newPersons
            persons = newPersons;


        }
        return persons[1];


    }

}
